<template>
  <div v-if="data" class="updatecar">
    <el-form ref="data" :model="this.data" label-width="100px">

      <!-- 车辆名称 -->
      <el-form-item label="车辆名称">
        <el-col :span="4">
          <el-input v-model="data.car_name" placeholder="请输入内容"></el-input>
        </el-col>
      </el-form-item>
      <!-- 车辆价格 -->
      <el-form-item label="车辆价格">
        <el-input v-model="data.car_price" placeholder="98、189、"></el-input>
      </el-form-item>
      <!-- 车辆评分 -->
      <el-form-item label="车辆评分">
        <el-select v-model="data.car_score"> 
          <el-option label="5分" value="5"></el-option>
          <el-option label="4分" value="4"></el-option>
        </el-select>
      </el-form-item>
      <!-- 车辆特点 -->
      <el-form-item label="车辆特点">
        <el-input
          v-model="data.car_feature"
          placeholder="美观/大气/舒适/豪华"
        ></el-input>
      </el-form-item>
      <!-- 是否热销 -->
      <el-form-item label="车辆是否热销">
        <el-select v-model="data.car_ishot"> 
          <el-option label="热销" value="1"></el-option>
          <el-option label="正常" value="0"></el-option>
        </el-select>
      </el-form-item>
      <!-- 车辆所属类别 -->
                  <!-- 车辆图片 -->
      <el-form-item label="车辆图片">
        <el-image :src="data.car_img"/>
      </el-form-item>
        <el-form-item>
    <el-button type="primary" @click="goUpdate">立即修改</el-button>
    <el-button @click.native="goback()">返回</el-button>
  </el-form-item>
    </el-form>
    
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: null,
    };
  },
  props: ["id"],
  mounted() {
    console.log(this.id);
    this.getdata(this.id);
  },
  methods: {
    // 回退
    goback(){
      this.$router.push('/managecar')
    },
    // 更新
    goUpdate(){
      console.log(this.data.car_name);
      console.log(this.data.car_price);
      console.log(this.data.car_score);
      console.log(this.data.car_feature);
      console.log(this.data.car_ishot);
      let params = `name=${this.data.car_name}&price=${this.data.car_price}&score=${this.data.car_score}&feature=${this.data.car_feature}&ishot=${this.data.car_ishot}&id=${this.id}`

      this.axios.post('/admin/renewal',params)
      .then(res => {
        // console.log(res)
        if(res.data.code == 200 ){
          this.$message({
          message: '修改成功',
          type: 'success'
        });
        }
      })
    },
    getdata(id) {
      this.axios.post("/admin/updatecars", `carid=${id}`).then((res) => {
        console.log(res.data.cardata[0]);
        this.data = res.data.cardata[0];
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.updatecar{
  width: 60%;
  margin: auto;
  border: 1px solid #ccc;
}
</style>
